package cn.swenty.backstage.framework.datasource;

import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.springframework.stereotype.Component;

@Component
@Aspect
public class DynamicDateSourceAspect {
	
	/*@Pointcut("execution (* com.potato.orm.mapper.*.select*(..)) || execution (* com.potato.orm.mapper.*.count*(..)) ")
    public void readMethodPointcut() {}

    @Pointcut("execution (* com.potato.orm.mapper.*.insert*(..)) || execution (* com.potato.orm.mapper.*.update*(..)) || execution (* com.potato.orm.mapper.*.delete*(..))")
    public void writeMethodPointcut() {}*/

    @Before("masterMethodPointcut()")
    public void switchReadDateSource(){
        //System.out.println("============切换到读数据源===========");
        DataSourceContextHolder.setType(DataSourceContextHolder.DATA_SOURCE_MASTER);
    }

    @Before("slaveMethodPointcut()")
    public void switchWriteDateSource(){
        //System.out.println("=============切换到写数据源==========");
        DataSourceContextHolder.setType(DataSourceContextHolder.DATA_SOURCE_SLAVE);
    }

}
